/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef PEPTIDE_H
#define PEPTIDE_H

#include <string>
#include <string.h>	// for C's memcpy

#include "aminoacid.h"

/**
  a peptide is a vector of unsigned char.
  It should usually start (in the stored mode) with 1 for nterm and finish with 28 for cterm
  However, values stored can be outised of the range [1:28] and then stand for modified amino acids. The correspondance with the modification is given by a PeptideModifier object
  
	@author Alexandre Masselot,,, <alex@alex-laptop>
*/
using namespace std;
namespace bol{
class Peptide{
  unsigned char *m_sequence;
  int m_length;

  void fromString(const string& seq);

public:
    Peptide(){
      m_sequence=0;
    }

    /**
     * build a peptide based on a casual AA sequence (normal letters)
     * @param seq aminocid sequence
     */
    Peptide(const string seq);

    /**
     * copy constructor (duplicates the unsigned char* m_sequence)
     * @param pept 
     */
    Peptide(const Peptide& pept){
      m_sequence=new unsigned char[pept.length()+1];
      memcpy(m_sequence, pept.sequence(), pept.length()+1);
      m_length=pept.length();
    }

    /**
     * constructor from a subset position in  the original peptide (dupicating the m_sequence)
     * start and end reduced aminoacid will be added if needed
     * @param pept 
     * @param pos 
     * @param  
     */
    Peptide(const Peptide& pept, const int pos, const int len);
    /**
     * destructor deletes the unsigned char*
     */
    ~Peptide();

    /**
     * 
     * @return peptide sequence
     */
    virtual double getMass()const{
      return getMass(sequence());
    }
  
    /**
     * compute the mass for a sequence
     * @param seq apeptide sequence (char can also be modified aminoacid)
     * @return whole seq mass
     */
    static double getMass(unsigned char* seq);

  /**
   * set the sequence as a unsigned char* and set the length accordingly
   * @param theValue 
   */
  void setSequence(unsigned char* theValue) {
      m_sequence = theValue;
      for(m_length=0; m_sequence[m_length]; m_length++){}
  }
  
  /**
   * set the sequence from a string (previous one is deleted)
   * @param theValue 
   */
  //todo profile to see if a more clecver data structure qould be helpful to limit new/delete
  void setSequence(const string& seq);

  unsigned char* sequence() const {
      return m_sequence;
  }


  /**
   * 
   * @return  the sequence length (thus the unsigned char*, ending with 0 will have effective size length()+1)
   */
  int length() const {
      return m_length;
  }
  

};

}
#endif
